/*
 * ShipLoader.java
 *
 * Created on 22. April 2007, 18:12
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package de.tor.loaders;

import com.golden.gamedev.object.sprite.VolatileSprite;
import de.tor.obj.TorridityGameObject;
import de.tor.obj.impl.GatlingGun;
import de.tor.obj.impl.ProjectileFactory;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

/**
 *
 * @author Charon
 */
public class Player extends TorridityGameObject{
    
    final int LEFT = 0;
    final int CENTER = 1;
    final int RIGHT = 5;
    private int iMaxHealth = 10000;
    private int iHealth = 10000;
    
    private int iMaxShield = 1000;
    private int iShield = 1000;
    
    double speedX = 0;
    double speedY = 0;
    
    private boolean collideTop = false;
    private boolean collideBottom = false;
    private boolean collideLeft = false;
    private boolean collideRight = false;
    private Interface mInterface = null;
    
    /** Creates a new instance of ShipLoader */
    public Player(Level level, BufferedImage[] pView) {
        super(level, pView);
    }
    
    public void setInterface(Interface pInterface){
        mInterface = pInterface;
    }
    
    public void initObject() {
     //  setAnimationFrame(2,5);
        setLayer(50);
        GatlingGun leftGun = new GatlingGun(this);
        GatlingGun rightGun = new GatlingGun(this);
        leftGun.setObjectRelativePosition(-26, -3);
        rightGun.setObjectRelativePosition(26,-3);
        rightGun.setProjectile(ProjectileFactory.GATLING_PIERCER_PROJECTILE);
        leftGun.setProjectile(ProjectileFactory.GATLING_SHRAPNELL_PROJECTILE);
        addWeapon(leftGun);
        addWeapon(rightGun);
    }
    
    public void updateTorridityGameObject(long l) {
        if (getLevel().keyDown(KeyEvent.VK_LEFT)) {
            if(!collideLeft){
                speedX = -0.2;
             //   setAnimationFrame(0,1);
            }else{
                speedX = 0;
             //   setAnimationFrame(2,5);
            }
            
        }else if (getLevel().keyDown(KeyEvent.VK_RIGHT)){
            if(!collideRight){
                speedX = 0.2;
            //   setAnimationFrame(6,7);
            }else{
                speedX = 0;
           //     setAnimationFrame(2,5);
            }
        }else{
            speedX = 0;
         //   setAnimationFrame(2,5);
            setAnimate(true);
            setLoopAnim(true);
        }
        
        if (getLevel().keyDown(KeyEvent.VK_UP)) {
            if(!collideTop){
                speedY = -0.2;
            }else{
                speedY = 0;
            }
        }else if (getLevel().keyDown(KeyEvent.VK_DOWN)){
            if(!collideBottom){
                speedY = 0.2;
            } else{
                speedY = 0;
            }
        }else{
            speedY = 0.05;
            collideBottom = false;
            collideTop = false;
            collideLeft = false;
            collideRight = false;
        }
        
        setHorizontalSpeed(speedX);
        setVerticalSpeed(speedY);
        
        if(getScreenX() <= 0){
            setX(0);
            collideLeft = true;
        }
        if(getScreenX() >= getLevel().getWidth() - getWidth()){
            setX(getLevel().getWidth() - getWidth());
            collideRight = true;
        }
        
        if(getScreenY() <= 0){
            setY(getLevel().getLevelPosition());
            collideTop = true;
        }
        
        if(getY() >= getLevel().getLevelBottom() - getHeight()){
            setLocation(getX(), getLevel().getLevelBottom() - getHeight());
            collideBottom = true;
        }
        
        if (getLevel().keyDown(KeyEvent.VK_CONTROL)) {
            setShoothing(true);
        }else{
            setShoothing(false);
        }
    }
    
    public boolean isDestructable() {
        return true;
    }
    
    public int getHealth() {
        return iHealth;
    }
    
    public int getMaxHealth(){
        return iMaxHealth;
    }
    
    public void doDamage(int v){
        int damage = v;
        if(damage >= iShield){
            damage -= iShield;
            iShield = 0;
        }else{
            iShield -= damage;
            damage = 0;
        }
        
        iHealth -= damage;
    }
    
    public int getMaxShield(){
        return iMaxShield;
    }
    
    public int getShield(){
        return iShield;
    }
    
    public int getCollisionDamage() {
        return 100;
    }
    
    public VolatileSprite getDestructionAnimation(){
        return null;
    }
}
